import {INIT_HEIGHT, INIT_WIDTH} from "@example/views/drag/const";

export function createDraggableItem(item, data = {}) {
  return {
    id: ZY.rid(),
    style: {
      // backgroundColor: Color()
    },
    conStyle: item.conStyle,
    activated: false,
    data: {

      ...data,

      reload: true,
      draggable: true,
      com_w: INIT_WIDTH,
      com_h: INIT_HEIGHT,
      w: INIT_WIDTH,
      h: INIT_HEIGHT,
      ...item.data(),
      pos: {
        l: 0,
        t: 0,
        w: INIT_WIDTH,
        h: INIT_HEIGHT
      }
    }
  }
}

export let dragCommonMixin = {
  methods: {
    reloadItem(item) {
      item.data.reload = false
      setTimeout(() => {
        item.data.reload = true
      }, 1000)
    },
    // collect
    drag__collect(item, w, h, l, t) {
      // console.log(item)
      item.data.w = w
      item.data.h = h
      item.data.pos = {
        l,
        t,
        w,
        h
      }
      this.reloadItem(item)
    },
    drag__move(item, l, t) {
      item.data.pos.l = l
      item.data.pos.t = t
    }
  }
}
